﻿@model Wicresoft.UnifyShow.Portal.Models.BSAddModel
@{
    ViewBag.Title = "添加业务系统";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
    string error = (string)ViewBag.error;
    bool post = ViewBag.Post ?? false;
}
<div class="right_title2">
    <a href="/Navigate/Index">首页</a> ><span>添加业务系统</span></div>
<div class="index_lr">
    @if (post && string.IsNullOrWhiteSpace(error))
    {
        <script type="text/javascript">

            $(document).ready(function () {
                alert("添加成功。")
            });
        </script> 
    }
    @if (post && !string.IsNullOrWhiteSpace(error))
    { 
        <span style="color: Red" id="errorInfo1">@error 已经存在同名业务系统。</span>
    }
    <span style="color: Red" id="errorInfo"></span>
    <ul>
        <li class="index_lr2_M">
            <div class="index_lrA_title ui-icons">
                <h3>
                    添加业务系统</h3>
            </div>
            @using (Html.BeginForm())
            {
                <div class="index_pt_bg">
                    <table>
                        <tbody>
                            <tr>
                                <td width="8%">
                                    <label>
                                        系统名称：</label>
                                </td>
                                <td width="22%">
                                    @Html.EditorFor(model => model.SystemName)
                                </td>
                                <td width="8%">
                                    <label>
                                        系统分类：</label>
                                </td>
                                <td width="22%">
                                    @Html.DropDownList("SystemCategroy", (IEnumerable<SelectListItem>)ViewData["Categories"])
                                </td>
                            </tr>
                            <tr>
                                <td valign="top">
                                    <label>
                                        供应商信息：</label>
                                </td>
                                <td colspan="3">
                                    @Html.TextAreaFor(model => model.VendorInfo, new { cols = 66 })
                                </td>
                            </tr>
                            <tr>
                                <td valign="top">
                                    <label>
                                        资产信息：</label>
                                </td>
                                <td colspan="3">
                                    @Html.TextAreaFor(model => model.AssetInfo, new { cols = 66 })
                                </td>
                            </tr>
                            <tr>
                                <td valign="top">
                                    <label>
                                        运维信息：</label>
                                </td>
                                <td colspan="3">
                                    @Html.TextAreaFor(model => model.OperateInfo, new { cols = 66 })
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <fieldset>
                        <legend>地市：全选<input type="checkbox" value="全选" id="allSites" /></legend>
                        <div id="sites">
                            @{
                List<Wicresoft.UnifyShow.Portal.Models.US_SiteAccessModel> uslist = Model.US_SiteAccessList;
                for (int i = 0; i < uslist.Count; i++)
                {
                                <label>@uslist[i].Alias：</label>
                                @Html.EditorFor(model => model.US_SiteAccessList[i].IsAccess);
                                @Html.HiddenFor(model => model.US_SiteAccessList[i].ID)
                                @Html.HiddenFor(model => model.US_SiteAccessList[i].Alias)
                }
                            }
                        </div>
                    </fieldset>
                    <p>
                        <input type="submit" value="添加" id="addSubmit" />
                    </p>
                </div>
            }
        </li>
    </ul>
</div>
@section LeftMenu{
    <li><a href="@Url.Action("CreateUser", "AdminPermission")">
        创建用户</a></li>
    <li><a href="@Url.Action("Index", "AdminPermission")">配置用户</a></li>
    <li class="VNavLeaf ui-icons">添加业务系统</li>
    <li><a href="@Url.Action("Index", "AdminBSMaintain")">维护业务系统</a></li>
    <li><a href="@Url.Action("Admin", "AdminDocument")">常用资源管理</a></li>
    <li><a href="@Url.Action("Index", "AdminOther")">其他管理</a></li>
    @*Javascript向导 参考  当UserSites.count>3时，一次取出，否则分别取出。可以仿造权限 来选择 业务系统范围    
    device 增删改查  列表  通过dialog 进行增加和 编辑*@
}
@section ScriptAndCss{
    @*    <script src="../../Scripts/jquery-1.4.4-vsdoc.js" type="text/javascript"></script>*@
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").submit(function () {
                var error = ""
                var isContain = 0;
                if ($("#SystemName").val() == "") error += "系统名称不能为空。";
                var sites = $(":checkbox", "#sites");
                var siteLength = sites.length;
                for (var i = 0; i < siteLength; i++) {
                    if ($(sites[i]).attr("checked") == true) {
                        isContain = 1;
                    }
                }
                if (isContain == 0) {
                    error += "至少选择一个地市。";
                }

                if (error != "") {
                    $("#errorInfo").html(error);
                    return false;
                }
                //$("#errorInfo1").empty();
                return true;
            });
            $("#allSites").change(function () {
                var sites = $(":checkbox", "#sites");
                if ($(this).attr("checked") == true) {
                    sites.each(function () {
                        $(this).attr("checked", true);
                    });
                }
                else {
                    sites.each(function () {
                        $(this).removeAttr("checked");
                    });
                }
            });
        });
    
    
    </script>
}
